package com.qfedu.defect.reception.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.common.R;
import com.qfedu.defect.reception.dto.DefectReceptionDto;
import com.qfedu.defect.reception.pojo.DefectReception;
import com.qfedu.defect.reception.service.DefectReceptionService;
import com.qfedu.defect.task.dto.DefectTaskDto;
import com.qfedu.defect.task.pojo.DefectTask;
import com.qfedu.defect.task.service.DefectTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/defectReception")
public class DefectReceptionController {

    @Autowired
    private DefectReceptionService defectReceptionService;

    @GetMapping
    public R<Page<DefectReception>> getDefectReceptions(DefectReceptionDto receptionDto){
        return R.ok(defectReceptionService.getDefectReceptions(receptionDto));
    }

    @PostMapping
    public R<Boolean> addDefectReception(@RequestBody DefectReception defectReception){
//        defectTask.setState(StringUtils.hasLength(defectTask.getDefectUser()) ? 1 : 0);
        return R.ok(defectReceptionService.save(defectReception));
    }

    @PutMapping
    public R<Boolean> updateDefectReception(@RequestBody DefectReception defectReception){
//        defectTask.setState(StringUtils.hasLength(defectTask.getDefectUser()) ? 1 : 0);
        return R.ok(defectReceptionService.updateById(defectReception));
    }

    @DeleteMapping("/{id}")
    public R<Boolean> deleteDefectReception(@PathVariable("id") Long id){
        return R.ok(defectReceptionService.removeById(id));
    }
}
